package com.future.controller;

import com.future.allUtils.constants.PermissionConstants;
import com.future.domain.DTO.AnswerDetailDTO;
import com.future.domain.Result;
import com.future.service.IQuestionnaireService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/student")
@Api(tags = "学生端问卷管理")
public class QuestionnaireControllerForS {

    @Resource
    private IQuestionnaireService questionnaireService;

    @PostMapping("/judge/{questionnaireId}")
    @ApiOperation("提交问卷，进行评分")
    @PreAuthorize("hasAuthority('" + PermissionConstants.STUDENT_HEALTH_FILL + "')")
    public Result judge(@RequestBody List<AnswerDetailDTO> answerList, @PathVariable String questionnaireId) throws Exception {
        return questionnaireService.judge(answerList,questionnaireId);
    }


    /**
     *  分页查询，获取问卷信息
     * @param pageNum 页码
     * @param pageSize 每页条数
     * @return Result
     */
    @GetMapping("/getByPage")
    @ApiOperation("分页查询，获取没有填写的问卷信息")
    @PreAuthorize("hasAuthority('" + PermissionConstants.STUDENT_HEALTH_VIEW + "')")
    public Result getByPage(Integer pageNum, Integer pageSize) {
        return questionnaireService.getAllQuestionnaireByPage(pageNum, pageSize);
    }
}
